<?php
/**
 * Created by PhpStorm.
 * 商家充值操作日志
 * User: caicm
 * Date: 2017/6/26
 * Time: 14:32
 */

namespace WMApi\Model;


use Think\Model;

class WmSellerRechargeLogModel extends Model {

    /**
     * 写入充值操作日志
     * Created By caicm
     * @param int $seller_id 商家id
     * @param int $money 金额
     * @param int $pay_id 支付方式
     * @param string $recharge_sn 充值单号
     * @return mixed
     */
    public function add_recharge_log($seller_id=0, $money=0, $pay_id=0, $recharge_sn=''){

        $data = array(
            'seller_id' => $seller_id,
            'money' => $money,
            'pay_id' => $pay_id,
            'recharge_sn' => $recharge_sn,
            'pay_state' => 0,
            'pay_number' => '',
            'add_time' => gmtime(),
            'source' => get_source(),
            'version' => get_version(),
        );

        return $this->data($data)->add();

    }

    /**
     * 查询充值日志详情
     * Created By caicm
     * @param $pay_id 支付方式
     * @param $out_trade_no 充值单号
     * @return mixed
     */
    public function find_log_info($pay_id, $out_trade_no){

        $where = array(
            'recharge_sn' => $out_trade_no,
            'pay_id' => $pay_id
        );

        return $this->where($where)->find();

    }

    /**
     * 修改充值记录状态
     * Created By caicm
     * @param int $id 记录id
     * @param string $trade_no 交易流水号
     * @return bool
     */
    public function update_log_state($id=0, $trade_no=''){

        $where = array(
            'id' => $id
        );

        $data = array(
            'pay_state' => 1,
            'pay_number' => $trade_no,
            'pay_time' => gmtime()
        );

        return $this->where($where)->data($data)->save();

    }
}